package com.metaverse.backend.exception;

import java.util.Objects;
import java.util.function.Supplier;

public class BusinessException extends RuntimeException implements Supplier<BusinessException> {
    private static final long serialVersionUID = 3779880207424189309L;

    /**
     * 针对任何形式的错误码
     */
    private Object code = -1;

    public BusinessException(String error) {
        super(error);
    }

    public BusinessException(String error, Object code) {
        super(error);
        this.code = code;
    }


    @Override
    public BusinessException get() {
        return this;
    }


    /**
     * 获取code
     * @return
     */
    public Object getCode(){
        return code;
    }

    /**
     * 获取code
     * @return
     */
    public String getStringCode(){
        return Objects.toString(code, "");
    }

}
